package maiyatian.videolive.fragment.personCenter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import maiyatian.videolive.ConstentInfo;
import maiyatian.videolive.IActivity;
import maiyatian.videolive.IFragment;
import maiyatian.videolive.R;
import maiyatian.videolive.activity.PersonCenterActivity;
import maiyatian.videolive.activity.SettingActivity;
import maiyatian.videolive.activity.WebviewActivity;
import maiyatian.videolive.application.IApp;
import maiyatian.videolive.fragment.setting.AboutUsFragment;
import maiyatian.videolive.fragment.setting.AccountSafeFragment;
import maiyatian.videolive.fragment.setting.BlackListFragment;
import maiyatian.videolive.fragment.setting.PushManageFragment;

/**
 * Created by 王中阳 on 2016/5/10.
 */
@ContentView(R.layout.content_setting)
public class SettingListFragment extends IFragment implements View.OnClickListener {
    public static final String TAG = "SettingListFragment";
    PersonCenterActivity mycontext;
    @ViewInject(R.id.back)
    ImageView back;
    @ViewInject(R.id.accountSafe)
    RelativeLayout accountSafe;
    @ViewInject(R.id.push)
    RelativeLayout push;
    @ViewInject(R.id.blackList)
    RelativeLayout blackList;
    @ViewInject(R.id.aboutApp)
    RelativeLayout aboutApp;
    @ViewInject(R.id.feedback)
    RelativeLayout feedback;
    @ViewInject(R.id.clearCache)
    RelativeLayout clearCache;
    @ViewInject(R.id.logout)
    TextView logout;

    public SettingListFragment() {

    }

    public static SettingListFragment newInstance() {
        SettingListFragment fragment = new SettingListFragment();
        return fragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mycontext = (PersonCenterActivity) context;

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        accountSafe.setOnClickListener(this);
        push.setOnClickListener(this);
        blackList.setOnClickListener(this);
        aboutApp.setOnClickListener(this);
        feedback.setOnClickListener(this);
        logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IApp.getInstance().exitApp(); //退出登录
            }
        });
        clearCache.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO: 2016/5/10 清理缓存
            }
        });
    }


    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.accountSafe:
                intent.setClass(getActivity(), SettingActivity.class);
                intent.putExtra(IActivity.PAGETO, AccountSafeFragment.TAG);
                break;
            case R.id.push:
                intent.setClass(getActivity(), SettingActivity.class);
                intent.putExtra(IActivity.PAGETO, PushManageFragment.TAG);
                break;
            case R.id.blackList:
                intent.setClass(getActivity(), SettingActivity.class);
                intent.putExtra(IActivity.PAGETO, BlackListFragment.TAG);
                break;
            case R.id.aboutApp:
                intent.setClass(getActivity(), SettingActivity.class);
                intent.putExtra(IActivity.PAGETO, AboutUsFragment.TAG);
                break;
            case R.id.feedback:
                intent.setClass(getActivity(), WebviewActivity.class);
                intent.putExtra(IActivity.PAGETO, ConstentInfo.FEEDBACK);
                break;
        }
        mycontext.startActivity(intent);
    }
}
